package com.fanbuchi.fukua.application;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.fanbuchi.fukua.greendao.DaoMaster;
import com.fanbuchi.fukua.greendao.DaoSession;
import com.fanbuchi.fukua.logger.Log;
import com.fanbuchi.fukua.manager.DaoManager;
import com.fanbuchi.fukua.manager.LocationManager;
import com.fanbuchi.fukua.manager.MapperManager;
import com.fanbuchi.fukua.manager.OauthManager;
import com.fasterxml.jackson.databind.ObjectMapper;

import cn.jpush.android.api.JPushInterface;


/**
 * Created by killerzhangsan on 2015/5/19.
 */
public class SuperApp extends Application{

    static SuperApp mSuperApp;

    @Override
    public void onCreate() {
        super.onCreate();
        mSuperApp = this;
        //ButterKnife.setDebug(BuildConfig.DEBUG);

        /*if (BuildConfig.DEBUG && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            openStrictMode();
        }*/
        Fresco.initialize(this);
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);

    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }


    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void openStrictMode() {
        /*StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectCustomSlowCalls()

                .detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().penaltyFlashScreen()// API等级11
                .build());*/
     /*   StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectCustomSlowCalls()
                .detectNetwork().penaltyLog().penaltyFlashScreen()// API等级11
                .build());*/

        /*StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());*/
    }

    /**
     * @title 实例管理
     * @return
     */
    public static final SuperApp getApplication(){
        return mSuperApp;
    }

    /**
     * @title getDaoMaster 管理
     * @param context
     * @return DaoMaster
     */
    public static DaoMaster getDaoMaster(Context context){
        return  DaoManager.getDaoMaster(context);
    }

    /**
     * @title getDaoSession 管理
     * @param context
     * @return DaoSession
     */
    public static DaoSession getDaoSession(Context context){
        return  DaoManager.getDaoSession(context);
    }

    /**
     * db 关闭
     */
    public static void safeClose(){
        DaoManager.safeClose();
    }

    /**
     * @title 位置管理
     * @return
     */
    public static final LocationManager getLocationManager(){
        return LocationManager.getInstance();
    }

    /**
     * @title Json转换管理
     * @return
     */
    public static final ObjectMapper getMapper(){
        return MapperManager.getMapper();
    }





    public static final  PackageInfo getVersion() {
        PackageInfo info=null;
        try {
            PackageManager manager = mSuperApp.getPackageManager();
            info = manager.getPackageInfo(mSuperApp.getPackageName(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return info;
    }

}
